export class Quaternion {
    constructor(w, x, y, z) {
        this.w = w;
        this.x = x;
        this.y = y;
        this.z = z;
    }

    // 计算四元数的共轭
    conjugate() {
        return new Quaternion(this.w, -this.x, -this.y, -this.z);
    }

    // 四元数乘法
    multiply(q) {
        let w = this.w * q.w - this.x * q.x - this.y * q.y - this.z * q.z;
        let x = this.w * q.x + this.x * q.w + this.y * q.z - this.z * q.y;
        let y = this.w * q.y - this.x * q.z + this.y * q.w + this.z * q.x;
        let z = this.w * q.z + this.x * q.y - this.y * q.x + this.z * q.w;
        return new Quaternion(w, x, y, z);
    }
}

